#include "D3D9_PCH.h"
#include "VisibleComponent.h"
#include "D3D9Actor.h"
#include "D3D9EffectManager.h"

CD3DActor::CD3DActor(void)
	: m_pVisibleComponent(NULL)
	, m_vPosition(0,0,0)
	, m_rRotation(0,0,0)
	, m_fScale(1)
{
	m_hMaterial = g_pEffectManager->getMaterial( _T("DefaultMaterial") );
}


CD3DActor::~CD3DActor(void)
{
	SAFE_DELETE(m_pVisibleComponent);
}

void CD3DActor::Render() const {
	assert( m_hMaterial.isValid() );

	static FLOAT time=0;
	if ( m_pVisibleComponent != NULL ) {		

		D3DXMATRIX view, proj, mat;
		g_pDevice->GetTransform( D3DTS_VIEW, &view );
		g_pDevice->GetTransform( D3DTS_PROJECTION, &proj );
		D3DXMatrixMultiply( &mat, &view, &proj );

		D3DXMATRIX matTransform;
		D3DXMatrixAffineTransformation( &matTransform, m_fScale, NULL, &(m_rRotation.toQuaternion()), &m_vPosition );
		//g_pDevice->SetTransform( D3DTS_WORLD, &matTransform );
		D3DXMatrixMultiply( &mat, &matTransform, &mat );

		m_hMaterial->setMatrix( "matToScreen", &mat );

		m_hMaterial->Render( "Default", m_pVisibleComponent );
	}
}

BOOL CD3DActor::setMaterial( TString MaterialName ) {
	return FALSE;
}